package game.frame;

import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoLabel;
import game.bean.PlayerInfo;
import game.sev.PlayerInfoSev;
import game.utils.FileUtils;

import javax.swing.*;
import java.awt.*;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.8
 * Time: 11:04
 * Description: 排行榜
 */
public class Leaderboard extends JFrame {
    private JLabel lb = new JLabel("排行榜");
    private JLabel c;
    private JLabel e;
    private JButton button = new JButton("返回主界面");


    public Leaderboard() {
        this.setLayout(null);

        JLabel jlImg = new JLabel();
        //  Image img = new ImageIcon("img/success.png").getImage();
        //  img = img.getScaledInstance(400, 700, 1);
        init();
        jlImg.setIcon(new ImageIcon("img/success.png"));
        jlImg.setBounds(0, 0, 650, 650);
        this.add(jlImg);

        this.setSize(650, 650);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
    }

    /**
     * 生成排行榜
     */
    private void init() {
        lb.setBounds(280, 50, 200, 50);
        this.add(lb);
        lb.setForeground(Color.WHITE);
        lb.setFont(new Font("Dialog", 1, 30));
        button.setBounds(150, 480, 400, 50);
        this.add(button);
        button.setOpaque(false);
        button.setContentAreaFilled(false);

        int x = 150, y = 50;
        int count = 0;
        for (PlayerInfo p : PlayerInfoSev.list) {
            y += 50;
            c = new JLabel(p.getName());
            x += 300;
            e = new JLabel(p.getNum() + "");
            e.setBounds(x, y, 200, 50);
            x -= 300;
            c.setBounds(x, y, 200, 50);
            e.setForeground(Color.WHITE);
            c.setForeground(Color.WHITE);
            e.setFont(new Font("Dialog", 1, 25));
            c.setFont(new Font("Dialog", 1, 25));
            this.add(c);
            this.add(e);
            count++;
            if (count == 5) {
                break;
            }

        }

        button.addActionListener(e -> {
            new StartFrame();
            this.dispose();
        });
    }

//    public static void main(String[] args) {
//        new Leaderboard();
//    }

}
